//ESP8266 串口通讯

#define led 16
char receive_data = -1;

void setup() {
    
	//设置管脚为输出模式 初始化化为高电平
  pinMode(led, OUTPUT);
	digitalWrite(led, HIGH);
    
	// 初始化串口，并开启调试信息
  Serial.begin(115200);    
}

void loop() {
   
    //如果串口有数据
    while(Serial.available())
    {
      receive_data = Serial.read();
      
      if(receive_data == 'a') //发送 a 开灯
      {
        digitalWrite(led, LOW);
        Serial.println("led on"); //带换行打印
      }
      if(receive_data == 'b') //发送 b 关灯
      {
        digitalWrite(led, HIGH);
        Serial.println("led off "); 
      }
     
     
    }
    Serial.print("-"); //不带换行打印
    delay(1000);
    	
}
